import { DataTypes, Model, Optional } from 'sequelize';
import sequelize from '@/config/database';

/**
 * 参数配置表 sys_config
 * 对应Java实体：com.ruoyi.system.domain.SysConfig
 */
export interface SysConfigAttributes {
  /** 参数主键 */
  configId: number;
  /** 参数名称 */
  configName: string;
  /** 参数键名 */
  configKey: string;
  /** 参数键值 */
  configValue: string;
  /** 系统内置（Y是 N否） */
  configType: string;
  /** 备注 */
  remark?: string;
  /** 创建者 */
  createBy?: string;
  /** 创建时间 */
  createTime?: Date;
  /** 更新者 */
  updateBy?: string;
  /** 更新时间 */
  updateTime?: Date;
}

export interface SysConfigCreationAttributes extends Optional<SysConfigAttributes, 'configId'> {}

export class SysConfig extends Model<SysConfigAttributes, SysConfigCreationAttributes> implements SysConfigAttributes {
  public configId!: number;
  public configName!: string;
  public configKey!: string;
  public configValue!: string;
  public configType!: string;
  public remark?: string;
  public createBy?: string;
  public createTime?: Date;
  public updateBy?: string;
  public updateTime?: Date;
  
  // 时间戳
  public readonly createdAt!: Date;
  public readonly updatedAt!: Date;
}

SysConfig.init(
  {
    configId: {
      type: DataTypes.INTEGER.UNSIGNED,
      autoIncrement: true,
      primaryKey: true,
      comment: '参数主键',
    },
    configName: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: '参数名称',
    },
    configKey: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: '参数键名',
      unique: true,
    },
    configValue: {
      type: DataTypes.STRING(500),
      allowNull: false,
      comment: '参数键值',
    },
    configType: {
      type: DataTypes.STRING(1),
      allowNull: false,
      comment: '系统内置（Y是 N否）',
      defaultValue: 'N',
    },
    remark: {
      type: DataTypes.STRING(500),
      allowNull: true,
      comment: '备注',
    },
    createBy: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: '创建者',
    },
    createTime: {
      type: DataTypes.DATE,
      allowNull: true,
      comment: '创建时间',
    },
    updateBy: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: '更新者',
    },
    updateTime: {
      type: DataTypes.DATE,
      allowNull: true,
      comment: '更新时间',
    },
  },
  {
    sequelize,
    tableName: 'sys_config',
    modelName: 'SysConfig',
    timestamps: true,
    createdAt: 'createTime',
    updatedAt: 'updateTime',
    comment: '参数配置表',
  }
);

export default SysConfig; 